package cmdb

import (
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
	"minefieldplatform-go/app/service/cmdb"
	"strings"
)

// StorageList 显示存储信息列表
func StorageList(r *ghttp.Request) {
	storageList, count := cmdb.GetStorageList()

	r.Response.WriteJson(g.Map{
		"code":  0,
		"msg":   "",
		"count": count,
		"data":  storageList,
	})
}

func StorageUpdate(r *ghttp.Request) {
	var data = g.Map{
		"id":           r.Get("id"),
		"ip":           r.Get("ip"),
		"cpu_cores":    r.Get("cpu"),
		"total_memory": r.Get("memory"),
		"disk":         r.Get("disk"),
		"area":         r.Get("area"),
		"node_status":  r.Get("node_status"),
	}
	cmdb.StorageUpdateData(data, data["id"])
}

func StorageDel(r *ghttp.Request) {
	id := r.Get("id")
	cmdb.StorageDelData(id)
}

func StorageAdd(r *ghttp.Request) {
	var data = g.Map{
		"ip":           r.Get("ip"),
		"cpu_cores":    r.Get("cpu"),
		"total_memory": r.Get("memory"),
		"disk":         r.Get("disk"),
		"area":         r.Get("area"),
		"node_status":  r.Get("node_status"),
	}
	cmdb.StorageAddData(data)
}

func StorageDelAll(r *ghttp.Request) {
	ids := r.GetFormArray("ids")
	a := strings.Split(ids[0], ",")
	v := g.Slice{}
	for _, i := range a {
		v = append(v, i)
	}

	cmdb.StorageDelAll(v)
}
